package com.um.jdy.platform.platform.controller;

import com.um.jdy.common.platform.entity.dto.MerchantDTO;
import com.um.jdy.common.platform.entity.po.Merchant;
import com.um.jdy.platform.platform.entity.dto.MerchantPageDTO;
import com.um.jdy.platform.platform.manager.MerchantManager;
import com.um.springboot.starter.annotation.ApiPermission;
import com.um.springboot.starter.annotation.RequestJson;
import com.um.springboot.starter.annotation.TokenRequired;
import com.um.springboot.starter.entity.Page;
import com.um.springboot.starter.orm.controller.BaseController;
import com.um.springboot.starter.orm.entity.Response;
import com.um.springboot.starter.orm.params.PageParams;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 控制器：平台商家表
 */
@RestController
@RequestMapping("/api/v1/cms/platform/merchant")
@Api(tags = "招商管理", description = "平台商家表")
@ApiPermission("merchant")
@TokenRequired
public class MerchantController extends BaseController<MerchantManager> {


    /**
     * 查询分页
     *
     * @param params
     * @return
     */
    @ApiPermission("page")
    @ApiOperation("分页查询")
    @PostMapping("/merchant_page")
    public Response<Page<Merchant>> getFeePage(@RequestBody MerchantPageDTO params) {
        PageParams pageParams = params.toPageParams(new String[]{"name","mobile","phone","type","parentId"},
                new String[]{"name","mobile","phone","type","parent_id"});
        return manager.getPage(pageParams);
    }

    /**
     * 查询一级运营商列表
     * @return
     */
    @ApiPermission("level1_list")
    @ApiOperation("查询一级运营商列表")
    @GetMapping("top_merchant_list")
    public Response getTopMerchantList(){
        return manager.getTopMerchantList();
    }

    @GetMapping("list/{type}")
    public Response getList(@PathVariable String type){
        return manager.getList(type);
    }

    @ApiPermission("add")
    @ApiOperation("新增")
    @PostMapping
    public Response<Merchant> add(@RequestBody MerchantDTO dto) {
        return manager.addEntity(dto);
    }

    @ApiPermission("update")
    @ApiOperation("更新")
    @PutMapping({"{id}"})
    public Response<Merchant> update(@PathVariable String id, @RequestBody MerchantDTO dto) {
        return manager.updateEntity(id, dto);
    }

    @ApiPermission("enable")
    @ApiOperation("启用、禁用")
    @PutMapping({"{id}/enable"})
    public Response<Object> enable(@PathVariable String id, @RequestParam String enable) {
        return manager.enable(id, enable);
    }

    @ApiPermission("delete")
    @ApiOperation("删除")
    @DeleteMapping({"{id}"})
    public Response<Object> delete(@PathVariable String id) {
        return manager.delete(id);
    }

    @ApiPermission("delete_all")
    @ApiOperation("批量删除")
    @DeleteMapping
    public Response<Object> deleteIds(@ApiParam(value = "删除的id",required = true) @RequestBody List<String> ids) {
        return manager.deleteIds(ids);
    }

    /**
     * 重置密码
     * @return
     */
    @ApiPermission("reset")
    @ApiOperation("重置密码")
    @PutMapping("/{userId}/reset_password")
    public Response resetPassword(@PathVariable String userId, @RequestJson String password){
        return manager.resetPassword(userId,password);
    }
}
